#include "Ray.h"

Ray::Ray(Vector3f &_origin, Vector3f &_direction)
{
	origin = _origin;
	direction = _direction;
}

bool Ray::testHit(/*const Object &object */)
{
	//This sphereRadius is a vector representing the sphere's three radii (x,y,z).
	tempOrig = this->origin / object->sphereRadius;
	tempDir = this->direction / object->sphereRadius;

	Vector3f originToSphere = object->position - this->tempOrig;
	float distOriginSphereSquared = originToSphere->.x * originToSphere.x + originToSphere.y * originToSphere.y + originToSphere.z + originToSphere.z;
	
	float projection = originToSphere.dotProduct(this->tempDir);
	
	float directionSquared = this->tempDir.x * this->tempDir.x + this->tempDir.y * this->tempDir.y + this->tempDir.z * this->tempDir.z;
	
	float result;
	
	result = directionSquared * distOriginSphereSquared - projection * projection;
	
	return (result <= object->radius * object->radius);
	//Normally we would check if the enemy is behind the ray, but we're culling detections so it's not
	//necessary.
}